package com.xsy.android.compose.we.component.ui.compose

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import com.xsy.android.compose.we.component.ui.page.contacts.ContactsList
import com.xsy.android.compose.we.component.ui.page.discovery.DiscoveryList
import com.xsy.android.compose.we.component.ui.page.home.HomePage
import com.xsy.android.compose.we.component.ui.page.me.MeList
import kotlinx.coroutines.launch

/**
 *@author: xiaosy
 *时间: 2024/6/27
 *@Description: java类作用描述
 *@Version: 1.0
 **/
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MainPage(navController: NavHostController) {
    val pagerState = rememberPagerState(pageCount = { 4 })
    val scope = rememberCoroutineScope()
    Scaffold(bottomBar = {
        BottomAppBar(actions = {
            BottomNavigation(pagerState.currentPage) { page ->
                scope.launch {
                    pagerState.animateScrollToPage(page = page)
                }

            }
        })
    }) { innerPadding ->
        HorizontalPager(
            state = pagerState,
            modifier = Modifier
                .padding(innerPadding)
        ) { page ->
            when (page) {
                0 -> HomePage(navController = navController)
                1 -> ContactsList()
                2 -> DiscoveryList()
                3 -> MeList()
            }

        }
    }

}

fun pageCount(): Int {
    return 10
}
